package oa.hleast.xswl.controller.admin.pms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.enums.QueryModeEnum;
import oa.hleast.common.result.Result;
import oa.hleast.xswl.pojo.domain.pms.PmsUserPointThing;
import oa.hleast.xswl.service.pms.PmsUserPointThingService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "【系统管理】")
@RestController("AdminPmsUserPointThingController")
@RequestMapping("/api.admin/v1/pmsUserPointThings")
@Slf4j
@AllArgsConstructor
public class PmsUserPointThingController {

    private PmsUserPointThingService pmsUserPointThingService;

    @ApiOperation(value = "列表分页", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryMode", value = "查询模式", paramType = "query", dataType = "QueryModeEnum", dataTypeClass = QueryModeEnum.class),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping
    public Result list(
            String queryMode,
            Integer page,
            Integer limit) {
        QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode);
        switch (queryModeEnum) {
            default:
                LambdaQueryWrapper<PmsUserPointThing> queryWrapper = new LambdaQueryWrapper<PmsUserPointThing>()
                        .orderByAsc(PmsUserPointThing::getSort)
                        .orderByDesc(PmsUserPointThing::getGmtModified)
                        .orderByDesc(PmsUserPointThing::getGmtCreate);

                Page<PmsUserPointThing> result = pmsUserPointThingService.page(new Page<>(page, limit), queryWrapper);
                return Result.success(result.getRecords(), result.getTotal());
        }
    }

    @ApiOperation(value = "详情", httpMethod = "GET")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "Long", dataTypeClass = Long.class)
    @GetMapping("/{id}")
    public Result detail(@PathVariable Long id) {
        return Result.success(pmsUserPointThingService.getById(id));
    }

}
